package com.smart.sso.server.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smart.mvc.service.mybatis.impl.ServiceImpl;
import com.smart.sso.server.dao.OperationlogDao;
import com.smart.sso.server.model.Operationlog;
import com.smart.sso.server.model.RoleLog;
import com.smart.sso.server.service.OperationlogService;
import com.smart.sso.server.service.RoleLogService;

@Service("operationlogService")
public class OperationlogServiceImpl extends ServiceImpl<OperationlogDao, Operationlog, Integer>
		implements OperationlogService {
	@Resource
	private RoleLogService roleLogService;

	@Autowired
	public void setDao(OperationlogDao dao) {
		this.dao = dao;
	}
	
	public List<Operationlog> findByAppId(Integer appId, Integer roleId, Boolean isEnable) {
		List<Operationlog> operationlogList = dao.findByAppId(appId, isEnable);
		if (roleId != null) {
			List<RoleLog> roleLogList = roleLogService.findByRoleId(roleId);
			for (Operationlog operationlog : operationlogList) {
				for (RoleLog rl : roleLogList) {
					Integer rloperationId = rl.getOperationId();
					Integer oloperationId = operationlog.getId();
					if (rloperationId == oloperationId) {
						operationlog.setChecked(true);
						break;
					}
				}
			}
		}
		return operationlogList;
	}
}
